package com.siwei.mes.entity.experiment.fineAggregate;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.common.util.NullUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 细骨料-筛分析
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class FineAggregateSfx {
    @ApiModelProperty(value = "烘干筛分后试样重量")
    private String hgsfhsyzl = "";
    @ApiModelProperty(value = "筛面面积")
    private String smmj = "";
    @ApiModelProperty(value = "第一份试样重量")
    private String dyfsyzl = "";
    @ApiModelProperty(value = "第二份试样重量")
    private String defsyzl = "";
    @ApiModelProperty(value = "细度模数1")
    private String xdms1 = "";
    @ApiModelProperty(value = "细度模数2")
    private String xdms2 = "";
    @ApiModelProperty(value = "细度模数平均值")//1
    private String xdmspjz = "";
    @ApiModelProperty(value = "10.0mm以上颗粒质量")
    private String ysklzl10 = "";
    @ApiModelProperty(value = "10.0mm以上颗粒含量")
    private String ysklhl10 = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "筛孔公称直径信息")
    private List<FineAggregateSfx.SfxInfo> sfxInfo = Collections.singletonList(new FineAggregateSfx.SfxInfo());


    @Data
    @Accessors(chain = true)
    @ApiModel("筛孔公称直径信息")
    public static class SfxInfo {
        @ApiModelProperty(value = "筛孔公称直径")
        private String skgjzj = "";
        @ApiModelProperty(value = "第一次筛余量")
        private String syl1 = "";
        @ApiModelProperty(value = "第二次筛余量")
        private String syl2 = "";
        @ApiModelProperty(value = "第一次分计筛余")
        private String fjsy1 = "";
        @ApiModelProperty(value = "第二次分计筛余")
        private String fjsy2 = "";
        @ApiModelProperty(value = "第一次累计筛余")
        private String ljsy1 = "";
        @ApiModelProperty(value = "第二次累计筛余")
        private String ljsy2 = "";
        @ApiModelProperty(value = "累计筛余平均值")//1
        private String ljsyppjz = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        FineAggregateSfx entity = new FineAggregateSfx();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, FineAggregateSfx.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, FineAggregateSfx.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        FineAggregateSfx entity = JsonUtils.getObject(objJson, FineAggregateSfx.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getXdmspjz()) || "null".equals(entity.getXdmspjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(FineAggregateSfx entity, Map<String, Object> data) {
        if (data.get("S1") != null) {
            entity.setHgsfhsyzl(NullUtils.ifNull(data.get("S1")));
        }
        if (data.get("S2") != null) {
            entity.setYsklzl10(NullUtils.ifNull(data.get("S2")));
        }
        if (data.get("S3") != null) {
            entity.setYsklhl10(NullUtils.ifNull(data.get("S3")));
        }
        if (data.get("S4") != null) {
            entity.setDyfsyzl(NullUtils.ifNull(data.get("S4")));
        }
        if (data.get("S27") != null) {
            entity.setDefsyzl(NullUtils.ifNull(data.get("S27")));
        }
        List<FineAggregateSfx.SfxInfo> sfxInfoList = entity.getSfxInfo();
        for (FineAggregateSfx.SfxInfo sfxInfo : sfxInfoList) {
            String skgjzj = sfxInfo.getSkgjzj();
            if ("5.00".equals(skgjzj)) {
                if (data.get("S5") != null) {
                    sfxInfo.setSyl1(NullUtils.ifNull(data.get("S5")));
                }
                if (data.get("S6") != null) {
                    sfxInfo.setFjsy1(NullUtils.ifNull(data.get("S6")));
                }
                if (data.get("S7") != null) {
                    sfxInfo.setLjsy1(NullUtils.ifNull(data.get("S7")));
                }
                if (data.get("S28") != null) {
                    sfxInfo.setSyl2(NullUtils.ifNull(data.get("S28")));
                }
                if (data.get("S29") != null) {
                    sfxInfo.setFjsy2(NullUtils.ifNull(data.get("S29")));
                }
                if (data.get("S30") != null) {
                    sfxInfo.setLjsy2(NullUtils.ifNull(data.get("S30")));
                }
                if (data.get("S51") != null) {
                    sfxInfo.setLjsyppjz(NullUtils.ifNull(data.get("S51")));
                }
            }
            if ("2.50".equals(skgjzj)) {
                if (data.get("S8") != null) {
                    sfxInfo.setSyl1(NullUtils.ifNull(data.get("S8")));
                }
                if (data.get("S9") != null) {
                    sfxInfo.setFjsy1(NullUtils.ifNull(data.get("S9")));
                }
                if (data.get("S10") != null) {
                    sfxInfo.setLjsy1(NullUtils.ifNull(data.get("S10")));
                }
                if (data.get("S31") != null) {
                    sfxInfo.setSyl2(NullUtils.ifNull(data.get("S31")));
                }
                if (data.get("S32") != null) {
                    sfxInfo.setFjsy2(NullUtils.ifNull(data.get("S32")));
                }
                if (data.get("S33") != null) {
                    sfxInfo.setLjsy2(NullUtils.ifNull(data.get("S33")));
                }
                if (data.get("S52") != null) {
                    sfxInfo.setLjsyppjz(NullUtils.ifNull(data.get("S52")));
                }
            }
            if ("1.25".equals(skgjzj)) {
                if (data.get("S11") != null) {
                    sfxInfo.setSyl1(NullUtils.ifNull(data.get("S11")));
                }
                if (data.get("S12") != null) {
                    sfxInfo.setFjsy1(NullUtils.ifNull(data.get("S12")));
                }
                if (data.get("S13") != null) {
                    sfxInfo.setLjsy1(NullUtils.ifNull(data.get("S13")));
                }
                if (data.get("S34") != null) {
                    sfxInfo.setSyl2(NullUtils.ifNull(data.get("S34")));
                }
                if (data.get("S35") != null) {
                    sfxInfo.setFjsy2(NullUtils.ifNull(data.get("S35")));
                }
                if (data.get("S36") != null) {
                    sfxInfo.setLjsy2(NullUtils.ifNull(data.get("S36")));
                }
                if (data.get("S53") != null) {
                    sfxInfo.setLjsyppjz(NullUtils.ifNull(data.get("S53")));
                }
            }
            if ("0.630".equals(skgjzj)) {
                if (data.get("S14") != null) {
                    sfxInfo.setSyl1(NullUtils.ifNull(data.get("S14")));
                }
                if (data.get("S15") != null) {
                    sfxInfo.setFjsy1(NullUtils.ifNull(data.get("S15")));
                }
                if (data.get("S16") != null) {
                    sfxInfo.setLjsy1(NullUtils.ifNull(data.get("S16")));
                }
                if (data.get("S37") != null) {
                    sfxInfo.setSyl2(NullUtils.ifNull(data.get("S37")));
                }
                if (data.get("S38") != null) {
                    sfxInfo.setFjsy2(NullUtils.ifNull(data.get("S38")));
                }
                if (data.get("S39") != null) {
                    sfxInfo.setLjsy2(NullUtils.ifNull(data.get("S39")));
                }
                if (data.get("S54") != null) {
                    sfxInfo.setLjsyppjz(NullUtils.ifNull(data.get("S54")));
                }
            }
            if ("0.315".equals(skgjzj)) {
                if (data.get("S17") != null) {
                    sfxInfo.setSyl1(NullUtils.ifNull(data.get("S17")));
                }
                if (data.get("S18") != null) {
                    sfxInfo.setFjsy1(NullUtils.ifNull(data.get("S18")));
                }
                if (data.get("S19") != null) {
                    sfxInfo.setLjsy1(NullUtils.ifNull(data.get("S19")));
                }
                if (data.get("S40") != null) {
                    sfxInfo.setSyl2(NullUtils.ifNull(data.get("S40")));
                }
                if (data.get("S41") != null) {
                    sfxInfo.setFjsy2(NullUtils.ifNull(data.get("S41")));
                }
                if (data.get("S42") != null) {
                    sfxInfo.setLjsy2(NullUtils.ifNull(data.get("S42")));
                }
                if (data.get("S55") != null) {
                    sfxInfo.setLjsyppjz(NullUtils.ifNull(data.get("S55")));
                }
            }
            if ("0.160".equals(skgjzj)) {
                if (data.get("S20") != null) {
                    sfxInfo.setSyl1(NullUtils.ifNull(data.get("S20")));
                }
                if (data.get("S21") != null) {
                    sfxInfo.setFjsy1(NullUtils.ifNull(data.get("S21")));
                }
                if (data.get("S22") != null) {
                    sfxInfo.setLjsy1(NullUtils.ifNull(data.get("S22")));
                }
                if (data.get("S43") != null) {
                    sfxInfo.setSyl2(NullUtils.ifNull(data.get("S43")));
                }
                if (data.get("S44") != null) {
                    sfxInfo.setFjsy2(NullUtils.ifNull(data.get("S44")));
                }
                if (data.get("S45") != null) {
                    sfxInfo.setLjsy2(NullUtils.ifNull(data.get("S45")));
                }
                if (data.get("S56") != null) {
                    sfxInfo.setLjsyppjz(NullUtils.ifNull(data.get("S56")));
                }
            }
            if ("筛底".equals(skgjzj)) {
                if (data.get("S23") != null) {
                    sfxInfo.setSyl1(NullUtils.ifNull(data.get("S23")));
                }
                if (data.get("S24") != null) {
                    sfxInfo.setFjsy1(NullUtils.ifNull(data.get("S24")));
                }
                if (data.get("S25") != null) {
                    sfxInfo.setLjsy1(NullUtils.ifNull(data.get("S25")));
                }
                if (data.get("S46") != null) {
                    sfxInfo.setSyl2(NullUtils.ifNull(data.get("S46")));
                }
                if (data.get("S47") != null) {
                    sfxInfo.setFjsy2(NullUtils.ifNull(data.get("S47")));
                }
                if (data.get("S48") != null) {
                    sfxInfo.setLjsy2(NullUtils.ifNull(data.get("S48")));
                }
                if (data.get("S57") != null) {
                    sfxInfo.setLjsyppjz(NullUtils.ifNull(data.get("S57")));
                }
            }
        }
        if (data.get("S26") != null) {
            entity.setXdms1(NullUtils.ifNull(data.get("S26")));
        }
        if (data.get("S49") != null) {
            entity.setXdms2(NullUtils.ifNull(data.get("S49")));
        }
        if (data.get("S50") != null) {
            entity.setXdmspjz(NullUtils.ifNull(data.get("S50")));
        }
        if (data.get("JPQ") != null) {
            entity.setDxjl(NullUtils.ifNull(data.get("JPQ")));
        }
    }
}
